public class NEWSentence implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private int nbWritings = 0;
	private String data;
	private Counter_itf cpt;
	
	public NEWSentence() {
		data = new String("");
		cpt = (Counter_itf) Client.lookup("Counter");
		if (cpt == null) {
			cpt = (Counter_itf) Client.create(new Counter());
			Client.register("Counter", cpt);
		}	
	}
	
	public void write(String text) {
		data = text;
		cpt.lock_write();
		cpt.write(++nbWritings);
		cpt.unlock();
	}
	public String read() {
		cpt.lock_read();
		nbWritings = cpt.read();
		cpt.unlock();
		return data;
	}
	
	public int getNbWritings() {
		return nbWritings;
	}
	
	public String toString() {
		return "Sentence is: "+data;
	}
	
}